package model

import (
	"cloud-disk/xorm"
	"time"
)

type RepositoryPool struct {
	Id        int64
	Identity  string
	Hash      string
	Name      string
	Ext       string
	Size      int32
	Path      string
	CreatedAt time.Time `xorm:"created"`
	UpdatedAt time.Time `xorm:"updated"`
	DeletedAt time.Time `xorm:"deleted"`
}

//TableName 指定表名
func (table RepositoryPool) TableName() string {
	return "repository_pool"
}

func (table RepositoryPool) GetRepositoryPoolByHash(hash string) (*RepositoryPool, bool, error) {
	repositoryPool := new(RepositoryPool)
	has, err := xorm.Xorm.Where("hash = ?", hash).Get(repositoryPool)
	if err != nil {
		return nil, false, err
	}
	return repositoryPool, has, err
}

func (table RepositoryPool) CreateRepositoryPool(rp *RepositoryPool) error {
	_, err := xorm.Xorm.Insert(rp)
	if err != nil {
		return err
	}
	return nil
}

func (table RepositoryPool) GetRepositoryPoolByIdentity(identity string) (rep *RepositoryPool, has bool, err error) {
	rep = new(RepositoryPool)
	has, err = xorm.Xorm.Where("identity = ?", identity).Get(rep)
	if err != nil {
		return nil, false, err
	}
	return rep, has, err
}
